import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ButtonPanel extends JPanel {
	
	public ButtonPanel(){
		this.addButton("Red", Color.RED);
		this.addButton("Green", Color.GREEN);
		this.addButton("Blue", Color.BLUE);
	}
	
	private void addButton(String buttonName, Color gColor){
		System.out.print(buttonName);
		JButton button = new JButton(buttonName);
		this.add(button);		
		
		ColorAction act = new ColorAction(gColor);
		button.addActionListener(act);		
	}
	
	private class ColorAction implements ActionListener{
		
		private Color bgrColor;
		
		public ColorAction(Color gColor){
			this.bgrColor = gColor;
		}
		
		public void actionPerformed(ActionEvent e) {
			setBackground(this.bgrColor);			
		}		
	}
}
